package com.app.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.app.model.Group;
import com.app.tourismmer.R;
import com.app.util.Util;

public class GroupArrayAdapter extends ArrayAdapter<Group> {
    
    private final LayoutInflater mInflater;
    
    public GroupArrayAdapter(Context context) {
        super(context, R.layout.list_group);
        mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
 
    public void setData(List<Group> data) {
        clear();
        if (data != null) {
            for (Group appEntry : data) {
                add(appEntry);
            }
        }
    }
    
    public void addList(List<Group> data) {
        if (data != null) {
            for (Group appEntry : data) {
                add(appEntry);
            }
        }
    }
    
    
    /**
     * Populate new items in the list.
     */
    @Override public View getView(int position, View convertView, ViewGroup parent) {
        View view;
 
        if (convertView == null) {
            view = mInflater.inflate(R.layout.list_group, parent, false);
        } else {
            view = convertView;
        }
 
        Group item = getItem(position);
//        ((ImageView)view.findViewById(R.id.image));
        ((TextView)view.findViewById(R.id.destination)).setText(item.getDestination());
        ((TextView)view.findViewById(R.id.purpose)).setText(item.getPurpose().getDescription());
        ((TextView)view.findViewById(R.id.date)).setText(Util.dateStringToString(item.getDate(), Util.FORMAT_DATE_JSON, Util.FORMAT_MONTH_YEAR));
 
        return view;
    }

}
